package cn.nawang.ebeim.api.service.impl;


import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.nawang.ebeim.api.comm.PageList;
import cn.nawang.ebeim.api.comm.Pages;
import cn.nawang.ebeim.api.domain.PushMessage;
import cn.nawang.ebeim.api.domain.User;
import cn.nawang.ebeim.api.repository.PushMessageRepository;
import cn.nawang.ebeim.api.repository.impl.PushMessageRepositoryImpl;
import cn.nawang.ebeim.api.service.PushMessageService;

/**
 * @ClassName: PushMessageServiceImpl
 * @Description: TODO
 * @author fanyb
 * @date Oct 14, 2015 2:42:09 PM
 * @version v1.0
 */
@Service("pushMessageService")
public class PushMessageServiceImpl implements PushMessageService{

  private static final Logger LOG = LoggerFactory.getLogger(PushMessageServiceImpl.class);
  
  @Autowired
  private PushMessageRepository pushMessageRepository;
  
  @Autowired
  private PushMessageRepositoryImpl pushMessageRepositoryImpl;

  @Override
  public boolean add(PushMessage pushMessage,User user) {
    try{
      pushMessage.setCreateTime(new Date().getTime());
      pushMessage.setCreateUserId(user.getId());
      pushMessageRepository.save(pushMessage);
      return true;
    }catch(Exception e){
      e.printStackTrace();
    }
    return false;   
  }

  @Override
  public PageList findPageList(Pages pages) {
    return pushMessageRepositoryImpl.findAllByPaging(pages);
  }

  @Override
  public List<PushMessage> findMoreThan(int id) {
    return pushMessageRepositoryImpl.findMoreThan(id);
  }

  @Override
  public void delete(int[] ids) { 
    pushMessageRepositoryImpl.delete(ids);
  }

  @Override
  public void update(PushMessage pushMessage) {
    PushMessage oldPushMessage=pushMessageRepositoryImpl.findPushMessage(pushMessage.getId());
    pushMessage.setCreateTime(oldPushMessage.getCreateTime());
    pushMessage.setCreateUserId(oldPushMessage.getCreateUserId());
    pushMessageRepository.save(pushMessage);   
  }

  @Override
  public PushMessage findOne(int id) {
    PushMessage pushMessage=pushMessageRepositoryImpl.findPushMessage(id);
    return pushMessage;
  }
  
}
